package com.haiyi.software.app;

import java.util.HashMap;
import java.util.Map;

import com.haiyi.software.app.basic.ActivityBasicGiftListView;
import com.haiyi.software.dao.ChatDAO;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class ActivitySetting extends Activity implements OnClickListener {

	private Button btn_setting_about, btn_setting_exit;

	private SharedPreferences sp;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_setting);

		initCom();
	}

	private void initCom() {

		this.btn_setting_about = (Button) this
				.findViewById(R.id.btn_setting_about);
		this.btn_setting_exit = (Button) this
				.findViewById(R.id.btn_setting_exit);

		this.btn_setting_about.setOnClickListener(this);
		this.btn_setting_exit.setOnClickListener(this);

	}

	@Override
	public void onClick(View v) {

		Intent intent;

		switch (v.getId()) {

		case R.id.btn_setting_about:

			intent = new Intent(this, ActivityAboutme.class);

			startActivity(intent);

			break;
		case R.id.btn_setting_exit:

			Builder builder = new AlertDialog.Builder(this);

			builder.setTitle("确认").setMessage("确定要退出当前帐号吗？")
					.setPositiveButton("是", okClick)
					.setNegativeButton("否", null).show();

			break;
		}
	}

	private DialogInterface.OnClickListener okClick = new DialogInterface.OnClickListener() {

		@Override
		public void onClick(DialogInterface dialog, int which) {

			sp = ActivitySetting.this.getSharedPreferences("WHOESYOU",
					Context.MODE_PRIVATE);

			Editor editor = sp.edit();
			editor.putString("USER_NAME", "");
			editor.putString("PASSWORD", "");
			editor.commit();

			if (MainApplication.getInstance().getmXMPPStream()
					.GetXMPPConnection().isConnected()) {
				MainApplication.getInstance().getmXMPPStream()
						.GetXMPPConnection().disconnect();
			}

			MainApplication.getInstance().setMineUserInfo(null);

			ChatDAO.getInstence().distoryDB();

			Intent intent = new Intent(ActivitySetting.this,
					LoginActivity.class);

			startActivity(intent);

		}

	};

}
